import { ref, computed } from "vue";
import bg from '@/static/images/game/airplane/bg.png';
import bgPlanet from '@/static/images/game/airplane/bg-planet.png';
import rocket from '@/static/images/game/airplane/rocket.png';
import rocketSmall from '@/static/images/game/airplane/rocket-small.png';
import bullet from '@/static/images/game/airplane/bullet.png';
import itemBg from '@/static/images/game/airplane/item-bg.png';
// ==============爆炸图片==============
import fram1 from '@/static/images/game/airplane/explosion/frame-1.png';
import fram2 from '@/static/images/game/airplane/explosion/frame-2.png';
import fram3 from '@/static/images/game/airplane/explosion/frame-3.png';
import fram4 from '@/static/images/game/airplane/explosion/frame-4.png';
import fram5 from '@/static/images/game/airplane/explosion/frame-5.png';
import fram6 from '@/static/images/game/airplane/explosion/frame-6.png';
import fram7 from '@/static/images/game/airplane/explosion/frame-7.png';
import fram8 from '@/static/images/game/airplane/explosion/frame-8.png';
import fram9 from '@/static/images/game/airplane/explosion/frame-9.png';
import fram10 from '@/static/images/game/airplane/explosion/frame-10.png';
import fram11 from '@/static/images/game/airplane/explosion/frame-11.png';
import fram12 from '@/static/images/game/airplane/explosion/frame-12.png';
import fram13 from '@/static/images/game/airplane/explosion/frame-13.png';
import fram14 from '@/static/images/game/airplane/explosion/frame-14.png';
import fram15 from '@/static/images/game/airplane/explosion/frame-15.png';
export default function() {
	const requireCount = ref(0);
	const loadedCount = ref(0);

	function loadImage(url) {
		const image = new Image();
		image.src = url;
		requireCount.value++;
		image.onload = () => {
			loadedCount.value++;
		}
		return image;
	}

	function loadImageA(urls) {
		const images = [];
		for (let i = 0; i < urls.length; i++) {
			images[i] = loadImage(urls[i]);
		}
		return images;
	}

	// function loadFrams(frams) {
	// 	const record = {};
	// 	Object.values(frams).forEach((path) => {
	// 		const split = path.split('/');
	// 		const file = split[split.length - 1];
	// 		const fileName = file.split('.')[0];
	// 		const fileSpilt = fileName.split('-');
	// 		const index = fileSpilt[fileSpilt.length - 1];
	// 		record[index] = path;
	// 	})
	// 	const list = Object.keys(record).map(k => Number(k)).sort((a, b) => a - b).map((k) => {
	// 		return record[k];
	// 	})
	// 	return loadImageA(list);
	// }
	const bgImg = loadImage(bg)
	const bgPlaneImg = loadImage(bgPlanet)
	const rocketImg = loadImage(rocket)
	const rocketSmallImg = loadImage(rocketSmall)
	const bulletImg = loadImage(bullet)
	const itemBgImg = loadImage(itemBg)
	const explosionFrams = loadImageA([fram1, fram2, fram3, fram4, fram5, fram6, fram7, fram8, fram9, fram10, fram11, fram12, fram13, fram14, fram15])
	const loadComplete = computed(() => {
		return requireCount.value == loadedCount.value;
	})
	return {
		bgImg,
		bgPlaneImg,
		bulletImg,
		explosionFrams,
		itemBgImg,
		rocketImg,
		rocketSmallImg,
		loadComplete
	}
}